package jdo.crud;


import java.io.IOException;
//import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.google.appengine.api.datastore.Transaction;

import jdo.entity.Tramway;
import jdo.pmf.PMF;

	/**
	 * Servlet implementation class ListServlet
	 */
	@SuppressWarnings("serial")
	public class AddTramwayServlet extends HttpServlet {
		
		
		protected void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {

			PersistenceManager pm = PMF.getPersistenceManager();
			
			String name = (String) req.getParameter("name");
			String coord_x = (String) req.getParameter("coord_x");
			String coord_y = (String) req.getParameter("coord_y");

			// Create a record
			Tramway tramway = new Tramway(name,coord_x,coord_y);
			pm.makePersistent(tramway);
			pm.close();
			res.sendRedirect("/administration.jsp?message=createdOK");
	
		}
		 
		public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			doGet(request,response);
		}
		 
	}
